package prettypenny;

/**
 *
 * @author Charlie
 */
/* TODO
 * Remove ^
 * Sort out the design!!!!
 * Error handling
 * 
 *
 */



/* DB Struture
     * car: carId, make, model, fuelType, regNum
     * carService: serviceID, clientId, carId, locationId, mechanicId, typeId, serviceDate, serviceTime, serviceDurationHour, description, price, bookingDate, mileage
     * client: clientId, forname, surname, dob, addLine1, addLine2, city, county, postcode, homeNum, mobileNum, email
     * location: locationId, branch
     * mechanic: mechanicId, forename, surname, mobNum
     * serviceType: typeId, typeOfService
     */
import java.awt.Color;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.concurrent.TimeUnit;

/*
 * Queries needed:
 * get client type via client name
 * search for client id based on client name (%LIKE%)
 * get car info from car reg (select * from car where reg = )
 * 
 */
public class BookingForm1 extends javax.swing.JPanel {
    private Connection con;
    private Statement stmt;
    private ResultSet rs;
    private Lists clients;
    private BookingList bookings;
    private Booking currBooking;
    private Mechanic mechanic;
    private MechanicList mechanics;
    private CarList cars;
    private Client currClient;
    boolean slider = true;


    public BookingForm1()  {
        initComponents();
        LoadData();
        clients = new Lists();
        mechanics = new MechanicList();
        bookings = new BookingList(mechanics);
        cars = new CarList(bookings);
        clientSlider.setMaximum(clients.getClientSize());
                System.out.println(mechanics.getPosition(16).getName());
        // default values
        currClient = clients.getFirst();
        UpdateForm();
        //
    }

    public void LoadData()  {
        try { 
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // server:port:database
            con = DriverManager.getConnection("jdbc:odbc:uni");
            stmt = con.createStatement(); 

        } catch(Exception ex) {
            System.out.println(ex.toString());
        } 
    }

    private void UpdateForm() {
     //   long startTime = new SimpleDateFormat("HHmmss").format(Calendar.getInstance().getTime());
        
        clientID.setText(""+currClient.getID());
        clientName.setText(currClient.getForename() + " " + currClient.getSurname());
        customerEmail.setText(currClient.getEmail());
        customerMobile.setText(currClient.getMobile());
        carID.setText("" + FindBooking(currClient.getID()).getCarID());
        mileage.setText("" + FindBooking(currClient.getID()).getMileage());
        mechanicName.setText(""+mechanics.getPosition(FindBooking(currClient.getID()).getMechanicID()).getName());
        mechanicMobile.setText(""+mechanics.getPosition(FindBooking(currClient.getID()).getMechanicID()).getMobile());
        if(cars.getPosition(FindBooking(currClient.getID()).getCarID()).getHireCar())
            typeLabel.setText("Internal");
        else
            typeLabel.setText("External");
        
      /*
         *   SimpleDateFormat formatter = new SimpleDateFormat("yyyy-mm-dd");
     SimpleDateFormat formatter2 = new SimpleDateFormat("dd-mm-yyyy");
Then when you put it in the form use the formatters to do the following:
 try {
            txtDate.setText(formatter2.format(formatter.parse(currentCar.getRegDate())));
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
         */
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-mm-dd");
        SimpleDateFormat formatter2 = new SimpleDateFormat("dd-mm-yyyy");
        Booking currBookings = FindBooking(currClient.getID());
        String testDate = currBookings.getServiceDate(); // TODO
        
      //  time.setText("" + FindBooking(currClient.getID()).getServiceTime().substring(11)); // .replace("-", "")
       // date.setText(""+ FindBooking(formatter.format(currClient.getID().getServiceDate().substring(0, 10)))); // use simpledateformat
        try {
            date.setText(formatter2.format(formatter.parse(testDate)));//TODO not working
        }catch(Exception ex) {
            System.out.println(ex.toString());
        } 
       // date.setText(""+ (FindBooking(currClient.getID()).getServiceDate().substring(0, 10).replace("-", "")));// working
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTimeInMillis(System.currentTimeMillis());

        if(Integer.parseInt(date.getText()) == rightNow.get(Calendar.DATE)) 
            timeUntil.setText("" + FindBooking(currClient.getID()).getServiceTime());
        if((Integer.parseInt(FindBooking(currClient.getID()).getServiceTime().substring(11).replace("-", "").replace(":", ""))/10000 - rightNow.get(Calendar.HOUR_OF_DAY)) > 0) // --
            timeUntil.setText((Integer.parseInt(FindBooking(currClient.getID()).getServiceTime().substring(11).replace(":", ""))/10000) - (rightNow.get(Calendar.HOUR_OF_DAY)) + "");
        else
            timeUntil.setText("NA");
       }
    private void UpdateClient(boolean slider) {  
        boolean match = false;
        Client matchedClient = null;
        if(slider) {
            currClient = clients.getPosition(clientSlider.getValue());
        } else {
            if(clientName.getText().length() > 0) {
       
            for (int i = 0; i<clients.getClientSize(); i++) { // go through all the clients

                for(int j = 0; clientName.getText().length()>=j; j++) {// go through each char of curr enterred name
                    // match by substring - wasting cpu cycles here 
                    if(!(clientName.getText().substring(0, j).equalsIgnoreCase(clients.getPosition(i).getName().trim().substring(0, j)))) { // 0 - number of chars gone through
                        match = false;
                        break; // should match first letter, if not go to next client
                    } else {
                        System.out.println(clientName.getText().substring(0, j));
                        System.out.println(clients.getPosition(i).getName().trim().substring(0, j));
                        match = true;
                    }
                   
                }
                if(match == true) {
                    System.out.println(clients.getPosition(i).getForename());
                    matchedClient = clients.getPosition(i);
                    break; // already found our match   
                }                                     
            }
            if(matchedClient != null) {
                currClient = matchedClient;
                System.out.println(matchedClient.getForename());
            } else
                System.out.println("No Match");
            }
        }
        UpdateForm();
    }  
    public Booking FindBooking(int client) {
          for(int i=0; i<bookings.getSize(); i++) {
            if(bookings.getPosition(i).getClientID() == currClient.getID()) {
                return bookings.getPosition(i);
            } 
        }
      return null;
    }
    private void updateType() {
        typeLabel.setText("" + FindBooking(currClient.getID()).getType());
        // use type id to find type - manual switch
    }
    public static void main(String args[]) throws Exception {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(BookingForm1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(BookingForm1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(BookingForm1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(BookingForm1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run()  {
                new BookingForm1().setVisible(true);
            }
        });
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jLabel15 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        typeLabel = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        clientName = new javax.swing.JTextField();
        clientID = new javax.swing.JTextField();
        carID = new javax.swing.JTextField();
        mileage = new javax.swing.JTextField();
        notes = new javax.swing.JTextField();
        carInfoButt = new javax.swing.JButton();
        clientSlider = new javax.swing.JSlider();
        clientNoLabel = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        mechanicName = new javax.swing.JTextField();
        customerMobile = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        mechanicMobile = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        customerEmail = new javax.swing.JTextField();
        jButton6 = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        time = new javax.swing.JTextField();
        date = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        timeUntil = new javax.swing.JTextField();

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 314, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 426, Short.MAX_VALUE)
        );

        jCheckBox1.setText("jCheckBox1");

        jLabel15.setText("jLabel15");

        setRequestFocusEnabled(false);

        jLabel1.setText("Client Name");

        jLabel2.setText("ClientID");

        jLabel3.setText("Car");

        jLabel4.setText("Mileage");

        jLabel5.setText("Notes");

        typeLabel.setForeground(new java.awt.Color(63, 6, 32));
        typeLabel.setText("Internal");

        jButton1.setText("Service History");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        clientName.setText("clientName");
        clientName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clientNameActionPerformed(evt);
            }
        });
        clientName.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                clientNameFocusLost(evt);
            }
        });
        clientName.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                clientNamePropertyChange(evt);
            }
        });
        clientName.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                clientNameKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                clientNameKeyTyped(evt);
            }
        });

        clientID.setText("clientID");
        clientID.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                clientIDPropertyChange(evt);
            }
        });

        carID.setText("carID");

        mileage.setText("0");
        mileage.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                mileagePropertyChange(evt);
            }
        });

        notes.setText("notes");

        carInfoButt.setText("Info");
        carInfoButt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                carInfoButtActionPerformed(evt);
            }
        });

        clientSlider.setMaximum(10);
        clientSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                clientSliderStateChanged(evt);
            }
        });
        clientSlider.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                clientSliderPropertyChange(evt);
            }
        });

        clientNoLabel.setText("Client No");

        jButton4.setText("View/Remove Bookings");

        jPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

        jLabel8.setText("Mechanic Mobile");

        jLabel6.setText("Mechanic");

        mechanicName.setText("clientName");

        customerMobile.setText("clientName");

        mechanicMobile.setText("clientName");

        jLabel7.setText("Client Contact Details");

        jLabel9.setText("Mechanic Details");

        jLabel10.setText("Client Mobile");

        jLabel11.setText("Client Email");

        customerEmail.setText("clientName");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(50, 50, 50)
                        .addComponent(mechanicName, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(337, 337, 337)
                        .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(jLabel10))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(mechanicMobile, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(customerEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(customerMobile, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                .addGap(210, 210, 210))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(81, 81, 81)
                        .addComponent(jLabel9))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(82, 82, 82)
                        .addComponent(jLabel7))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel11)))
                .addContainerGap(429, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(53, 53, 53)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(mechanicName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(mechanicMobile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(41, 41, 41)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(customerMobile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(customerEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(23, 23, 23)
                .addComponent(jLabel12)
                .addContainerGap(156, Short.MAX_VALUE))
        );

        jButton6.setText("Add Booking");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jLabel14.setText("Time");

        jLabel16.setText("Date");

        time.setText("jTextField1");

        date.setText("jTextField2");

        jLabel17.setText("Time Until");

        timeUntil.setText("jTextField3");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(clientSlider, javax.swing.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(152, 152, 152)
                                .addComponent(clientNoLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 152, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(20, 20, 20))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(84, 84, 84)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(notes, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(mileage, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
                                        .addGap(113, 113, 113))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(time, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(12, 12, 12)
                                        .addComponent(jLabel17)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(timeUntil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(date, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(typeLabel)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3))
                                .addGap(27, 27, 27)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(carID, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(clientID, javax.swing.GroupLayout.Alignment.LEADING))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jButton1)
                                        .addGap(10, 10, 10)
                                        .addComponent(carInfoButt))
                                    .addComponent(clientName, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jLabel14)
                            .addComponent(jLabel16))
                        .addGap(53, 53, 53)))
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(typeLabel)
                .addGap(53, 53, 53)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(clientName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(clientID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(carID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton1)
                        .addComponent(carInfoButt)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(mileage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(notes))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(time, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17)
                    .addComponent(timeUntil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel16)
                    .addComponent(date, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(clientNoLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(clientSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(45, 45, 45)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4)
                    .addComponent(jButton6))
                .addGap(26, 26, 26))
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 725, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        new ServiceHistory(bookings).setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void clientNamePropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_clientNamePropertyChange

    }//GEN-LAST:event_clientNamePropertyChange

    private void clientNameFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_clientNameFocusLost
        // less processing - or maybe it should be updated while typing to get realtime results 
    }//GEN-LAST:event_clientNameFocusLost

    private void mileagePropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_mileagePropertyChange
        try { // handle non-ints
            int miles = Integer.parseInt(this.mileage.getText());
            if( miles > 1000) {
                if((miles % 1000) == 0) {
                    mileage.setBackground(Color.red);
                }
            }
        } catch(Exception ex) {
            System.out.println(ex.toString());
        }
        
    }//GEN-LAST:event_mileagePropertyChange

    private void clientSliderPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_clientSliderPropertyChange

    }//GEN-LAST:event_clientSliderPropertyChange

private void clientIDPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_clientIDPropertyChange
    int clientInt = Integer.parseInt(clientID.getText());    
    clientID.setText(clients.getPosition(clientInt).getForename());
    clientName.setText(clients.getPosition(clientInt).getForename() + clients.getPosition(clientInt).getSurname());
    customerEmail.setText(clients.getPosition(clientInt).getEmail());
    customerMobile.setText(clients.getPosition(clientInt).getMobile());
}//GEN-LAST:event_clientIDPropertyChange

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
    new AddBooking(bookings, clients).setVisible(true);
}//GEN-LAST:event_jButton6ActionPerformed

private void clientSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_clientSliderStateChanged
        System.out.println(clientSlider.getValue());
        UpdateClient(true);
        clientNoLabel.setText(clients.getPosition(clientSlider.getValue()).getForename());
}//GEN-LAST:event_clientSliderStateChanged
   
private void carInfoButtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_carInfoButtActionPerformed
        new CarInfo(cars, currClient.getID(), bookings).setVisible(true);
}//GEN-LAST:event_carInfoButtActionPerformed

private void clientNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clientNameActionPerformed
        UpdateClient(false);
        
}//GEN-LAST:event_clientNameActionPerformed

private void clientNameKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_clientNameKeyTyped

}//GEN-LAST:event_clientNameKeyTyped

private void clientNameKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_clientNameKeyReleased
// UpdateClient(false); - too quick
}//GEN-LAST:event_clientNameKeyReleased

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField carID;
    private javax.swing.JButton carInfoButt;
    private javax.swing.JTextField clientID;
    private javax.swing.JTextField clientName;
    private javax.swing.JLabel clientNoLabel;
    private javax.swing.JSlider clientSlider;
    private javax.swing.JTextField customerEmail;
    private javax.swing.JTextField customerMobile;
    private javax.swing.JTextField date;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton6;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTextField mechanicMobile;
    private javax.swing.JTextField mechanicName;
    private javax.swing.JTextField mileage;
    private javax.swing.JTextField notes;
    private javax.swing.JTextField time;
    private javax.swing.JTextField timeUntil;
    private javax.swing.JLabel typeLabel;
    // End of variables declaration//GEN-END:variables
}
